<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.provincename" placeholder="省份名称"></el-input>
				</el-form-item>
				<el-form-item>
					<el-input v-model="filters.provincecode" placeholder="省份代码"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getProvincePage">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="provinces" highlight-current-row v-loading="listLoading" border max-height="620" style="width: 100%;">
			<el-table-column type="index" width="80" label="编号">
			</el-table-column>
			<el-table-column prop="provincename" label="省份名称" width="120"  >
			</el-table-column>
			<el-table-column prop="provincecode" label="省份代码" width="120"   >
			</el-table-column>
			<el-table-column prop="provincestatus" label="省份状态" width="120" :formatter="provincestatus"  >
			</el-table-column>
			<el-table-column prop="createtime" label="创建时间" min-width="200"  >
			</el-table-column>
			<el-table-column label="操作" min-width="150">
				<template scope="scope">
					<el-button size="small" @click="handleEdit(scope.$index, scope.row)">{{scope.row.provincestatus == "0" ? "启用" : "维护"}}</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
				layout="total,sizes,prev, pager, next"
				:total="total">
		</el-pagination>



	</section>
</template>

<script>
	import util from '../../common/js/util'
	import { getProvincePage,updateEnable} from '../../api/api';

	export default {
		data() {
			return {
				filters: {
                    provincename: '',
                    provincecode:''
				},
                provinces: [],
                total: 0,
                start:0,
                pageSize:10,
				listLoading: false,
			}
		},
		methods: {
			provincestatus: function (row, column) {
				return (row.provincestatus  == "0") ? "维护": ( row.provincestatus  == "1") ? "正常" : "未知";
			},
			//获取用户列表
            getProvincePage() {

                let para = {
                    start: this.start,
                    pageSize:this.pageSize,
                    provincename: this.filters.provincename,
                    provincecode:this.filters.provincecode
                };
                this.listLoading = true;
                getProvincePage(para).then((datas) => {
                    this.listLoading = false;
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.provinces = data.result;
                        this.total = data.totalCount;
                    }
                });
			}
			,handleCurrentChange:function(val){
				this.start = val - 1;
				this.getProvincePage();
			},
			handleSizeChange:function(val){
				this.pageSize = val;
				this.getProvincePage();
			},handleEdit:function(index,row){
				row.provincestatus = row.provincestatus == "0" ? "1" : "0"
				updateEnable(row).then(datas =>{
					let { message, code, data } = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					} else {
						this.getProvincePage();
					}
				});
			}
		},
		mounted() {
			this.getProvincePage();
		}
	}

</script>

<style scoped>

</style>
